package node;

import lexer.LexType;
import parser.Parser;

import java.io.IOException;

public class FuncFParamNode extends ASTNode {
    public final String name = "<FuncFParam>";
    boolean isArray = false;
    // FuncFParam → BType Ident ['[' ']']
    private final BTypeNode bTypeNode;
    private final String identNode;
    private int lineno;

    public FuncFParamNode(BTypeNode bTypeNode, String identNode) {
        this.bTypeNode = bTypeNode;
        this.identNode = identNode;
    }

    public FuncFParamNode(BTypeNode bTypeNode, String identNode, boolean isArray) {
        this.bTypeNode = bTypeNode;
        this.identNode = identNode;
        this.isArray = isArray;
    }

    @Override
    public void show() throws IOException {
        bTypeNode.show();
        Parser.parserWriter.write(LexType.IDENFR + " " + identNode + "\n");

        if (isArray) {
            Parser.parserWriter.write(LexType.LBRACK + " " + "[" + "\n");
            Parser.parserWriter.write(LexType.RBRACK + " " + "]" + "\n");
        }

        Parser.parserWriter.write(name + "\n");
    }

    public String getIdentNode() {
        return identNode;
    }

    public BTypeNode getbTypeNode() {
        return bTypeNode;
    }

    public int getLineno() {
        return lineno;
    }

    public void setLineno(int lineno) {
        this.lineno = lineno;
    }

    public boolean isArray() {
        return isArray;
    }

}
